package com.sunyard.utils;


import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhix.huang
 * @ClassName: ObjectToMap$
 * @PackageName: com.sydtech.bms.util$
 * @Description 对象转map
 * @date 2018/11/22$ 22:11$
 * @Version: V1.0
 **/
public class ObjectToMap {
    /**
     * Description
     */
    public static Map<String, String> objectToMap(Object obj) throws IllegalAccessException {
        Map<String, String> map = new HashMap<>();
        Class<?> clazz = obj.getClass();
        for (Field field : clazz.getDeclaredFields()) {
            field.setAccessible(true);
            String fieldName = field.getName();
            Object value = field.get(obj);
            if (null != value) {
                map.put(fieldName, value.toString());
            }
        }
        return map;

    }
}
